package com.gdut.gulimall.order.web;

import com.alipay.api.AlipayApiException;
import com.gdut.gulimall.order.config.AlipayTemplate;
import com.gdut.gulimall.order.service.OrderService;
import com.gdut.gulimall.order.vo.PayVo;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Drifiter
 * @create 2021-11-02 10:59
 */
@Controller
public class PayWebController {

    @Autowired
    AlipayTemplate alipayTemplate;

    @Autowired
    OrderService orderService;

    @ResponseBody
    @GetMapping(value = "/payOrder",produces = "text/html")
    public String payOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {
        /**
         * PayVo payVo = new Payvo();
         * payVo.setBody();//订单的备注
         * payVo.setOut_trade_no();//订单号
         * payvo.setSubject();//订单的主题
         * payVo.setTotal amount();
         */

        PayVo payVo = orderService.getOrderPay(orderSn);
        String pay = alipayTemplate.pay(payVo);

        System.out.println(pay);

        return pay;
    }

}
